using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FastPoster.DataProviders.DAO
{
	#region using
	using System.Data;
	using FastPoster.DataProviders.DTO;
    using System.Data.OleDb;
	#endregion

	public class BaiVietDaDangDAO : AbstractDAO
	{
		public BaiVietDaDangDAO(String strPath): base(strPath)
		{
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_BaiVietDaDang_SelectAll";
				base.FillDataSet(ref ds, "BaiVietDaDang");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_BaiVietDaDang_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				base.FillDataSet(ref ds, "BaiVietDaDang");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public bool Insert(BaiVietDaDangDTO obj)
		{
			try
			{
				base.sql = "usp_BaiVietDaDang_Insert";
				base.InitializeCommand();
				base.AddParameter("@IDBaiVietMau", OleDbType.Integer, 1000, obj.IDBaiVietMau);
				base.AddParameter("@IDBox", OleDbType.Integer, 1000, obj.IDBox);
				base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
				base.AddParameter("@NgayDang", OleDbType.Date, 1000, obj.NgayDang);
				return ExecuteStoredProcedure();
			}
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
		}

        public bool Update(BaiVietDaDangDTO obj)
        {
            try
            {
                base.sql = "usp_BaiVietDaDang_Update";
                base.InitializeCommand();
                base.AddParameter("@ID", OleDbType.Integer, 1000, obj.ID);
                base.AddParameter("@IDBaiVietMau", OleDbType.Integer, 1000, obj.IDBaiVietMau);
                base.AddParameter("@IDBox", OleDbType.Integer, 1000, obj.IDBox);
                base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
                base.AddParameter("@NgayDang", OleDbType.Date, 1000, obj.NgayDang);
                return ExecuteStoredProcedure();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }

		public bool Delete(int id)
		{
			try
			{
				base.sql = "usp_BaiVietDaDang_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				return ExecuteStoredProcedure();
			}
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
		}

		public DataSet SelectByIDBaiVietMau(int idbaivietmau)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_BaiVietDaDang_SelectByIDBaiVietMau";
				base.InitializeCommand();
				base.AddParameter("@IDBaiVietMau", OleDbType.Integer, 1000, idbaivietmau);
				base.FillDataSet(ref ds, "BaiVietDaDang");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByIDBox(int idbox)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_BaiVietDaDang_SelectByIDBox";
				base.InitializeCommand();
				base.AddParameter("@IDBox", OleDbType.Integer, 1000, idbox);
				base.FillDataSet(ref ds, "BaiVietDaDang");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

	}
}